package atguigu.day02;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

class MyThread implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"-------");
        return 1111;
    }
}


public class Calla4ble {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //一般方法
        MyThread myThread = new MyThread();

        FutureTask<Integer> futureTask = new FutureTask<Integer>(myThread);

        new Thread(futureTask,"线程1").start();
        System.out.println(futureTask.get());//这个一般放在最后。


        //使用lambda表达式创建callable线程
         new Thread(new FutureTask<Integer>(() ->{
            return 0;
        }),"线程").start();

        System.out.println();





    }


}
